import axios from 'axios'

// 创建 axios 实例
const api = axios.create({
    baseURL: import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000/api',
    timeout: 5000
})

export const foodApi = {
    // 获取所有食物
    getAllFoods() {
        return api.get('/foods')
    },
    
    // 根据分类获取食物
    getFoodsByCategory(category) {
        return api.get(`/foods/category/${category}`)
    },
    
    // 添加新食物
    addFood(foodData) {
        return api.post('/foods', foodData)
    },
    
    // 更新食物信息
    updateFood(id, foodData) {
        return api.put(`/foods/${id}`, foodData)
    },
    
    // 删除食物
    deleteFood(id) {
        return api.delete(`/foods/${id}`)
    }
}